package com.ljxt.dt.web.servlet.storemanagementservlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ljxt.dt.service.storemanagementservice.StoreService;
import com.ljxt.dt.service.storemanagementservice.impl.StoreServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 唐春劲
 * @version 1.0.0
 * @date 2020-05-18 9:52
 * @copyright 老九学堂
 */
@WebServlet("/submit")
public class SubmitOrder extends HttpServlet {
        private StoreService admin = new StoreServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
     String[] data =  req.getParameterValues("提交");

        //将单据状态改变
        if(data != null){
            int row = admin.submitOrder(data);
            ObjectMapper objectMapper = new ObjectMapper();
            resp.getWriter().write(objectMapper.writeValueAsString(row));
        }else{
            data = req.getParameterValues("审核");
            int row = admin.checkOrder(data);
            ObjectMapper objectMapper = new ObjectMapper();
            resp.getWriter().write(objectMapper.writeValueAsString(row));
        }



    }
}
